import { useWebCardCompStore } from '@/store/web/card-component';
import { defineStore, acceptHMRUpdate } from 'pinia'
// import { createSiteToServer, saveSiteDatasToServer } from '@/service/web/pages'
// import { getSiteDataToServer, getTempPreviewUrl, recoverSiteQrcode } from '@/service/web/user'
// import { useRouter } from 'vue-router'
// import router from '@/router';



declare interface IWebPanelComp {
  curTarget: any,
  curPanel: any,
  curPanelData: any
}

export const useWebPanelCompStore = defineStore('webPanelComp', {
  state: ():IWebPanelComp => {
    return {
      curTarget: {  // 当前编辑 item; ⚠️注意：仅暂存 itemId 以及 parentId
        itemId: '',
        parentId: '',
      },
      curPanel: -1,  // 当前弹层 panels[0]
      curPanelData: null,  // 当前弹层 data
    }
  },
  actions: {
    updateCurPanel(index) {
      // 0. use WebCard Comp
      const useWebCardComp = useWebCardCompStore();

      // 1. update curPanel
      this.curPanel = index;

      // 2. update cuePageData
      this.curPanelData = index > -1 ? useWebCardComp.siteData.panels[index] : null;
    },
    updatePanelLists(data) {
      // 0. use WebCard Comp
      const useWebCardComp = useWebCardCompStore();

      // 1. update Panel Lists
      useWebCardComp.updatePanelLists({data: data, index: this.curPanel});

      // 2. cur Panel Data
      this.curPanelData = data;
    },
    updateCurTarget(data) {
      this.curTarget = data;
    },

    /* beforeUnmount */
    clear(data) {
      // clear panel Components
      this.curTarget = {
        itemId: '',
        parentId: '',
      };
      this.curPanel = -1;
      this.curPanelData = null;
    },
  }
})
